using System;
using QueryBuilder.Core.Query;

namespace QueryBuilder.Core.Visualization.QueryVisualization
{
    internal class CreateVisualizableConstraintVisitor : IConstraintPresenter
    {
        private VisualizableConstraint visualizableConstraint;
        public VisualizableConstraint CreateFrom(Constraint constraint)
        {
            constraint.Accept(this);
            return this.visualizableConstraint;
        }

        public void Present(Expression expression)
        {
            var visualizableExpression = new VisualizableExpression {Comparison = expression.Comparison};
            foreach (var constraint in expression.Constraints)
            {
                visualizableExpression.AddChild(this.CreateFrom(constraint));
            }
            this.visualizableConstraint = visualizableExpression;
        }

        public void Present(Variable variable)
        {
            throw new NotImplementedException();
        }

        public void Present<T>(Variable<T> variable)
        {
            this.visualizableConstraint = new VisualizableVariable<T>(variable.Value);
        }

        public void Present(Aggregate aggregate)
        {
            throw new NotImplementedException();
        }

        public void Present(Column column)
        {
            throw new NotImplementedException();
        }

        public void Present(AliasedConstraint aliasedConstraint)
        {
            throw new NotImplementedException();
        }

        public void Present(Condition condition)
        {
            var visualizableExpression = new VisualizableCondition {Comparison = condition.Comparison};
            foreach (var constraint in condition.Constraints)
            {
                visualizableExpression.AddChild(this.CreateFrom(constraint));
            }
            this.visualizableConstraint = visualizableExpression;
        }
    }
}